import util from "./util"; // 获取指定收藏夹内容

function getUserCollect(type_id, page = 1) {
  return new Promise(resolve => {
    let data = {
      action: "collect",
      option: "list",
      openid: uni.getStorageSync("openid"),
      valueid: "",
      type_id,
      user_id: uni.getStorageSync("user_id"),
      page,
      size: 15
    };
    util.request('user.php', data, 'POST').then(res => {
      res.data.data.forEach((v, k) => {
        if (v.value != "undefined") v.value = JSON.parse(v.value);
      });
      return resolve(res.data.data);
    });
  });
}

function deleteCollect(ids) {
  return new Promise(resolve => {
    util.request("user.php", {
      action: "collect",
      option: "del_batch",
      ids,
      openid: uni.getStorageSync("openid") // user_id: wx.getStorageSync('user_id'),

    }, "POST").then(res => resolve(res));
  });
}

function moveCollect(new_id, ids) {
  return new Promise(resolve => {
    util.request("user.php", {
      action: "collect",
      option: "mod_batch",
      new_id,
      ids
    }, "POST").then(res => resolve());
  });
}

function top(ids) {
  return new Promise(resolve => {
    util.request("user.php", {
      action: "collect",
      option: "mod_top",
      ids
    }, "POST").then(res => resolve());
  });
}

module.exports = {
  getUserCollect,
  deleteCollect,
  moveCollect,
  top
};